module RPGBOY
  module_function
  MIN_NUM = 0
  
  MAX_NUM = 200
  
  def random_gift(show = true)
    $game_party.set_temp("rm",MIN_NUM + rand(MAX_NUM - MIN_NUM + 1))
    $game_party.incr_value("trc",1 + rand(2 - 1 + 1))
    container = [$data_items,$data_weapons,$data_armors]
    params = case $game_party.get("rm")
    when 1,5,9,13,17,21,25,29,33,37 # 全恢复胶囊
      # 0为物品,1为武器,2为防具以下为 物品,108号,1个(个数不填默认1个)
      [0,108,1]
    when 2,6,10,14,18,22,26,30,34,38 # 3为金钱,要加的钱数量
      [3,15000]
    when 3,7,11,15,19,23,27,31,35,39 # 金棒
      [0,33]
    when 4,8,12,16,20,24,28,32,36,40,163,168 # 迷之调制药水
      [0,257]
    when 41,68,98 # 幸运之子-七
      return random_gift(show) if $game_party.get("trc",0) < 10
      $game_party.set_temp("trc",0)
      [1,72]
    when 42,69,99 # 幸运之子-羊
      return random_gift(show) if $game_party.get("trc",0) < 10
      $game_party.set_temp("trc",0)
      [1,73]
    when 89,96 # V100单驱金刚
      return random_gift(show) if $game_party.get("trc",0) < 15
      $game_party.set_temp("trc",0)
      [2,805]
    when 43,48,53,58,63,192,194,175,172,177 # 7777金币
      [3,7777]
    when 44,49 # 狰狞衣
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,131]
    when 54,59 # 高效制空炮
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [2,784]
    when 64,164,169,174,179,191 # 手雷 * 5
      [0,20,5]
    when 45,50,55,60,65,173,178 # 终极突破因子
      [0,225]
    when 46,51,56,61,66,183,167 # 高级突破因子 * 2
      [0,224,2]
    when 193,170,162 # 秘制突破因子 * 1
      [0,287,1]
    when 160,165 # 皮甲
      [1,32]
    when 47 # 罪·手甲
      [1,158]
    when 52 # 罪·战甲
      [1,159]
    when 57 # 罪·披风
      [1,160]
    when 62 # 罪·头盔
      [1,161]
    when 67 # 罪·长靴
      [1,162]
    when 97 # 永世之罪
      [1,163]
    when 91 # 灵魂战甲
      [1,202]
    when 95 # 灵魂战靴
      [1,203]
    when 101,106,111,116,121,126,131,136,141 # 经验胶囊 A * 5
      [0,253,5]
    when 107,112,117,122,127,132,137,142,147 # 经验胶囊 B * 3
      [0,254,3]
    when 103,108,113,118,123,128,133,143,148 # 经验胶囊 C * 2
      [0,255,2]
    when 104,109,119,124,129,134,139,144,149 # 迷之果汁
      [0,256]
    when 105,110,115,120,125,130,135,140,145 # 外道兴奋剂 * 2
      [0,13,2]
    when 146,151 # 智慧之眼
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,139]
    when 102,152 # 狰狞甲
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,127]
    when 138,153 # 狰狞盔
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,128]
    when 114,154 # 狰狞靴子
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,129]
    when 150,155 # 狰狞手
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [1,130]
    when 188,156,185 # 战斗防护甲
      return random_gift(show) if $game_party.get("trc",0) < 5
      $game_party.set_temp("trc",0)
      [1,78]
    when 88,157,186  # 战斗披风
      return random_gift(show) if $game_party.get("trc",0) < 5
      $game_party.set_temp("trc",0)
      [1,141]
    when 200,158,187 # 战斗手甲
      return random_gift(show) if $game_party.get("trc",0) < 5
      $game_party.set_temp("trc",0)
      [1,86]
    when 100,199,189 # 制空爆射炮
      return random_gift(show) if $game_party.get("trc",0) < 12
      $game_party.set_temp("trc",0)
      [2,788]
    when 198,159 # 幸运777
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [2,491]
    when 69,74,68,73,181,182,161,166,171,176 # 普通界限突破因子 * 3
      [0,223]
    when 70,75 # 全恢复胶囊 * 5
      $game_party.set_temp("trc",3)
      [0,108,5]
    when 80,85,190,197,90,92,93,94 # 废铁1T * 4
      [0,208,4]
    when 71,76,81,86,196,180 # 废铁1T * 2
      [0,208,2]
    when 72,77,82,83,84 # 5w 金币
      $game_party.set_temp("trc",5)
      [3,50000]
    when 87,78,79 # 10w 金币
      return random_gift(show) if $game_party.get("trc",0) < 10
      $game_party.set_temp("trc",0)
      [3,100000]
    end
    if params
      if params[0] < 3
        $game_party.gain_item(container[params[0]][params[1]],params[2] || 1)
        show_gain_window(params[0] + 1,params[1],params[2] || 1) if show
      else
        $game_party.gain_gold(params[1])
        show_gain_window(0,0,params[1]) if show
      end
      # temp random count
      $game_party.incr_value("trc")
    end
  end
  def show_gain_window(type,id,value = 0)
    snstar2006_66rpg = Window_Base.new((640-200)/2,(480-94)/2,200,94)
    snstar2006_66rpg.contents = Bitmap.new(snstar2006_66rpg.width - 32, snstar2006_66rpg.height - 32)
    if value >= 0
      gain_text = "获得"    
    else
      gain_text = "失去"
    end
    case type
    when 0
      gain_type = "金钱"
      if value >=0
        Audio.se_play($gain_gold_se,80,100)
      else
        Audio.se_play("Audio/SE/"+"Item1",80,100)
      end
    when 1
      gain_type = "物品"
      string = $data_items[id]
      if value >=0
        Audio.se_play($gain_item_se,80,100)
      else
        Audio.se_play($loss_item_se,80,100)
      end
    when 2
      gain_type = "武器"
      string = $data_weapons[id]
      if value >=0
        Audio.se_play($gain_weapon_se,80,100)
      else
        Audio.se_play($loss_weapon_se,80,100)
      end
    when 3
      gain_type = "装备"
      string = $data_armors[id]
      if value >=0
        Audio.se_play($gain_armor_se,80,100)
      else
        Audio.se_play($loss_armor_se,80,100)
      end
    end
    snstar2006_66rpg.contents.draw_text(0,0,160,30,gain_text+gain_type+"：")
    unless type == 0
      snstar2006_66rpg.draw_item_name(string, 0, 30, true)
      snstar2006_66rpg.contents.draw_text(0, 30, 160, 30, "×"+value.abs.to_s, 2)
    else
      snstar2006_66rpg.draw_icon(262, 20, 30,true)
      snstar2006_66rpg.contents.draw_text(0,30,165,30,value.abs.to_s + "  "+ Vocab.currency_unit, 2)
    end
    snstar2006_66rpg.opacity = 255 ###SR
    for i in 0..50
      Graphics.update
    end
    for i in 0..10
      snstar2006_66rpg.opacity -= 10
      snstar2006_66rpg.contents_opacity -= 10
      Graphics.update
    end
    snstar2006_66rpg.dispose
  end
end
#fr2随机码礼包